package com.konsung.ksdc.manager.machine;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.konsung.ksdc.R;
import com.konsung.ksdc.common.utils.ImageUtils;

import java.io.File;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 上传本体图片编辑放大Activity
 * Created by Administrator on 2016/3/29 0029.
 */
public class PicViewActivity1 extends Activity {
    public static final String PIC_FILE = "picFile";
    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.iv_delete)
    ImageView ivDelete;
    @Bind(R.id.iv_pic)
    ImageView ivPic;

    public static final int RESULT_BACK = 101;
    public static final int RESULT_DELETE = 102;
    private Bitmap bitmap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pic_view1);
        ButterKnife.bind(this);
        final File picFile = (File) getIntent().getSerializableExtra("picFile");
        ImageUtils imageUtils = new ImageUtils();
        bitmap = imageUtils.ratio(picFile.getPath());
        ivPic.setImageBitmap(bitmap);
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                setResult(PIC_VIEW_BACK);
                finish();
            }
        });

        ivDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra(PIC_FILE, picFile);
                setResult(RESULT_DELETE, intent);
                finish();
            }
        });
    }

    @Override
    protected void onDestroy() {
        if (bitmap != null) {
            bitmap.recycle();
            bitmap = null;
        }
        super.onDestroy();
    }
}
